/**
	 * 注册时检测用
	 */
	var jud  = false;
	function registFormCheck(){
	var emp = "不能为空";
	var fmt = "不符合规范";
	var name = $("#r_userName").val();
	console.log('id:'+ $('#userId').html());
	$("#r_userName").on("blur",function a(){
		
		function a(){
			var s = $("#r_userName").val();
			if(s.trim() == ''){
				$(".r_nameWaring").html(emp);
				$(".r_nameWaring").css({display:'block'});
				return false;
			}
			//验证用户名只能输入3-20个以字母开头、可带数字、“_”、“.”的字串
			if(!isRegisterUserName($("#r_userName").val())){
				$(".r_nameWaring").html("账号"+fmt);
				$(".r_nameWaring").css({display:'block'});
				return false;
			}else{
				if(s == name){
					return true;
				}
				var rv = false;
				$.getJSON('../CheckUserName.do',{
					r_userName:s
				},function(data,status){
					if(status){
						var fg = data[0].flag;
						if(fg == '1' || fg == 1){
							$(".r_nameWaring").html("此用户名已被注册");
							$(".r_nameWaring").css({display:'block'});
							rv =  false;
						}else{
							$(".r_nameWaring").html("用户名可以使用");
							$(".r_nameWaring").css({display:'block'});
							rv = true;
						}
						
					}
				});
				return rv;
			}
			return true;
		}
		
		jud = a();
		
	});
	
	$("#r_userName").focus(function(){
		$(".r_nameWaring").css({display:'none'});
	});
	
	
	//密码检测
	$("#r_passwd").on("blur",function(){
		function a(){
			var s = $("#r_passwd").val();
			if(s.trim() == ''){
				$(".r_passwdWaring").html(emp);
				$(".r_passwdWaring").css({display:'block'});
				return false;
			}
			//验证密码：以字母开头、数字字母组成，长度在6-12之间
			if(!isRegistPassword($("#r_passwd").val())){
				$(".r_passwdWaring").html("密码"+fmt);
				$(".r_passwdWaring").css({display:'block'});
				return false;
			}
			return true;
		}
		jud = a();
	});
	$("#r_passwd").focus(function(){
		$(".r_passwdWaring").css({display:'none'});
	});
	
	//真实姓名检测
	$("#r_realName").on("blur",function(){
		function a(){
			var s = $("#r_realName").val();
			if(s.trim() == ''){
				$(".r_realNameWaring").html(emp);
				$(".r_realNameWaring").css({display:'block'});
				return false;
			}
			return true;
		}
		jud = a();
	});
	$("#r_realName").focus(function(){
		$(".r_realNameWaring").css({display:'none'});
	});
	
	//手机号码检测
	$('#r_phone').on("blur",function(){
		function a(){
			var s = $("#r_phone").val();
			if(s.trim() == ''){
				$(".r_phoneWaring").html(emp);
				$(".r_phoneWaring").css({display:'block'});
				return false;
			}
			if(!regIsPhone($('#r_phone').val())){
				$(".r_phoneWaring").html("手机号"+fmt);
				$(".r_phoneWaring").css({display:'block'});
				return false;
			}
			return true;
		}
		jud = a();
	});
	$("#r_phone").focus(function(){
		$(".r_phoneWaring").css({display:'none'});
	});
	if(!regIsPhone($('#r_phone').val())){
		$(".r_phoneWaring").html("手机号"+fmt);
		$(".r_phoneWaring").css({display:'block'});
	}
	
	//email
	$('#r_email').on("blur",function(){
		function a(){
			var s = $("#r_email").val();
			if(s.trim() == ''){
				$(".r_emailWaring").html(emp);
				$(".r_emailWaring").css({display:'block'});
				return false;
			}
			if(!regIsEmail($('#r_email').val())){
				$(".r_emailWaring").html("email"+fmt);
				$(".r_emailWaring").css({display:'block'});
				return false;
			}
			return true;
		}
		jud = a();
	});
	$("#r_email").focus(function(){
		$(".r_emailWaring").css({display:'none'});
	});
	if(!regIsEmail($('#r_email').val())){
		$(".r_emailWaring").html("email"+fmt);
		$(".r_emailWaring").css({display:'block'});
	}
	//address
	$('#r_address').on("blur",function(){
		function a(){
			var s = $("#r_address").val();
			if(s.trim() == ''){
				$(".r_addressWaring").html(emp);
				$(".r_addressWaring").css({display:'block'});
				return false;
			}
			return true;
		}
		jud = a();
	});
	$("#r_address").focus(function(){
		$(".r_addressWaring").css({display:'none'});
	});
	
	return jud;
	
	}//
	
	
	$(function(){
		var aCity = {
				1 : "北京市",
				2 : "天津市",
				3 : "河北",
				4 : "山西",
				5 : "内蒙古",
				6 : "辽宁",
				7 : "吉林",
				8 : "黑龙江",
				9 : "上海市",
				10 : "江苏",
				11 : "浙江",
				12 : "安徽",
				13 : "福建",
				14 : "江西",
				15 : "山东",
				16 : "河南",
				17 : "湖北",
				18 : "湖南",
				19 : "广东",
				20 : "广西",
				21 : "海南",
				22 : "重庆市",
				23 : "四川",
				24 : "贵州",
				25 : "云南",
				26 : "西藏",
				27 : "陕西",
				28 : "甘肃",
				29 : "青海",
				30 : "宁夏",
				31 : "新疆",
				32 : "台湾",
				33 : "香港",
				34 : "澳门",
				35 : "国外"
			};
		
		$.each(aCity,function(key,val){
			$(".r_local_province").append("<option class="+key+">"+val+"</option>");
//			console.log(val);
		});
		
		//add local privence r_local_proveance
		//add 三级联动
		//1为寻找市
		//2县
		$(".r_local_province").change(function(){
			
			
			var ar = $(".r_local_province").val();
			var key = $('.r_local_province>option:selected').attr('class');
			console.log('val:'+$(".r_local_province").val()+' key:'+key);
			$.getJSON('../Local.do',{key:key,local:ar},function(data,status){
				
				if(status){
					$(".r_local_city").empty();
					for(var i =0 ;i<data.length;i++){
						$(".r_local_city").append("<option class="+data[i].ID+">"+data[i].TITLE+"</option>");
					}
					
				}
				
			});
			
		});
		
		$(".r_local_city").change(function(){
			
			
			
			var ar = $(".r_local_city").val();
			var key = $('.r_local_city>option:selected').attr('class');
			console.log('val:'+$(".r_local_city").val()+' key:'+key);
			$.getJSON('../Local.do',{key:key,local:ar},function(data,status){
				
				if(status){
					$(".r_local_country").empty();
					for(var i =0 ;i<data.length;i++){
						$(".r_local_country").append("<option class="+data[i].ID+">"+data[i].TITLE+"</option>");
					}
					
				}
				
			});
			
		});
		
		
		/**
		 * 出生日期用
		 */
		$(function(){
			
			for(var i=1980;i<2010;i++){
				$(".r_bir_year").append("<option>"+i+"</option>");
			}
			
			for(var i=1;i<=12;i++){
				$(".r_bir_month").append("<option>"+i+"</option>");
			}
			
			for(var i=1;i<32;i++){
				$(".r_bir_day").append("<option>"+i+"</option>");
			}
			
		})
		
	})
	
	
	$(function(){
		var n = registFormCheck();
		$('#update_user_btn').click(function(){
			console.log(n);
			if(registFormCheck()){
				//点击有效
				var name = $('#r_userName').val();
				var passwd = $('#r_passwd').val();
				var sex =  $('#r_sex input[name="sex"]:checked ').val();
				var phone = $('#r_phone').val();
				var email = $('#r_email').val();
				var pro = $('.r_local_province>option:selected').val();
				var city = $('.r_local_city>option:selected').val();
				var country = $('.r_local_country>option:selected').val();
				
				var year = $('.r_bir_year>option:selected').val();
				var month = $('.r_bir_month>option:selected').val();
				var day = $('.r_bir_day>option:selected').val();
				var bir = year+'-'+month+'-'+day;
				var add = $('#r_address').val();
				var realName = $('#r_realName').val();
				var id = $('#userId').html();
				
				console.log(name+'-'+passwd+'-'+sex+'-'+phone+'-'+email+'-'+pro+'-'+city+'-'+country+'-'+add+'-'+realName+'-'+bir+'-'+id);
				if(name!='undefine'||passwd!='undefine'||sex!='undefine'||phone!='undefine'||email!='undefine'||pro!='undefine'||city!='undefine'||add!='undefine'||realName != 'undefine'){
					console.log("ajax");
					$.getJSON('../UpUInfo.do',{
						flag:1,//update other
						id:id,
						name:name,
						passwd:passwd,
						realName:realName,
						sex:sex,
						phone:phone,
						email:email,
						provience:pro,
						city:city,
						country:country,
						address:add,
						bir:bir
					},function(data,status){
						if(status){
							//success
							var flag = data[0].flag;
							var msg = data[0].msg;
							console.log(flag+'---'+msg);
							if(flag == '1' || flag == 1){
								$('#registModal').modal('hide');
								$(".modal-body>h2").html("修改成功"+'<br>');//默认登陆，从session里面读取用户信息
								//model show
								$("#myModels").modal("show");
							}
						}
					});
				}
			}
		});
		
		
		$('#userPhotoBtn').click(function(){
			$(".partInfo").hide(1000);
			$(".headPart").show(1500);
		});
		$('#userInfoBtn').click(function(){
			
			$(".headPart").hide(1500);
			$(".partInfo").show(1000);
		});
		
		$('#inputfile').change(function(){
			var path = $('#inputfile').val();
			if(path != ''){
				console.log("12");
				$('#sbmitBtn').removeAttr('disabled');
			}
		});
		
	})
	
$(function(){
	//get id   
	$('#shopInfoUrl').click(function(){
		console.log('123');
		var id = $('#userId').html();	
		$.getJSON('../UserShopInfo',{
			id:id
		},function(data,status){
			if(status){
				for(var i in data){
					$('.shopInfoTb').append('<tr><td>'+data[i].ANIMAL_NAME+'</td><td>'+data[i].SALE_DATE+'</td><td>'+data[i].SALE_MONEY+'</td><td>'+data[i].FORM_STATUS+'</td></tr>');
				}
			}
		});
	});	
	
	
})
